package com.unience.ec2.eclipse.dialog;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;

import com.unience.aws.monitor.model.MonitorEc2Instance;
import com.unience.ddns.IpHelper;
import com.xerox.amazonws.ec2.ImageDescription;
import com.xerox.amazonws.ec2.ReservationDescription.Instance;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Ec2InstanceInfoDialog extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Label labelAmi;
	private Label labelReservation;
	private Label label1;
	private Composite composite2;
	private Composite composite1;
	private Text textIp;
	private Label labelUserData;
	private Text textUserData;
	private Label labelIp;
	private Text textMyId;
	private Text textDate;
	private Label LabelDate;
	private Button buttonAccept;
	private Text textType;
	private Label labelType;
	private Label labelPrivateDns;
	private Text textPrivateDns;
	private Text textPublicDns;
	private Label labelPublicDns;
	private Composite composite3;
	private Text textState;
	private Label labelState;
	private Text textReservation;
	private Text textId;
	private Label labelId;
	private Text textAmi;
	
	Instance instance;
	
	MonitorEc2Instance monitorInstance;

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			Ec2InstanceInfoDialog inst = new Ec2InstanceInfoDialog(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public Ec2InstanceInfoDialog(Shell parent, int style) {
		super(parent, style);
	}

	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
			GridLayout dialogShellLayout = new GridLayout();
			dialogShellLayout.numColumns = 4;
			dialogShell.setText("Instance Info " + instance.getInstanceId());
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(800, 600);
			{
				labelAmi = new Label(dialogShell, SWT.NONE);
				labelAmi.setText("Ami");
				GridData labelAmiLData = new GridData();
				labelAmi.setLayoutData(labelAmiLData);
			}
			{
				textAmi = new Text(dialogShell, SWT.BORDER);
				GridData textAmiLData = new GridData();
				textAmiLData.widthHint = 292;
				textAmiLData.heightHint = 17;
				textAmi.setLayoutData(textAmiLData);
				textAmi.setEditable(false);
			}
			{
				labelId = new Label(dialogShell, SWT.NONE);
				labelId.setText("InstanceId");
				GridData labelIdLData = new GridData();
				labelId.setLayoutData(labelIdLData);
			}
			{
				textId = new Text(dialogShell, SWT.BORDER);
				GridData textIdLData = new GridData();
				textIdLData.widthHint = 314;
				textIdLData.heightHint = 17;
				textId.setLayoutData(textIdLData);
				textId.setEditable(false);
			}
			{
				labelReservation = new Label(dialogShell, SWT.NONE);
				labelReservation.setText("Reservation");
				GridData labelReservationLData = new GridData();
				labelReservation.setLayoutData(labelReservationLData);
			}
			{
				textReservation = new Text(dialogShell, SWT.BORDER);
				GridData textReservationLData = new GridData();
				textReservationLData.widthHint = 293;
				textReservationLData.heightHint = 17;
				textReservation.setLayoutData(textReservationLData);
				textReservation.setEditable(false);
			}
			{
				labelState = new Label(dialogShell, SWT.NONE);
				labelState.setText("State");
				GridData labelStateLData = new GridData();
				labelState.setLayoutData(labelStateLData);
			}
			{
				textState = new Text(dialogShell, SWT.BORDER);
				GridData textStateLData = new GridData();
				textStateLData.widthHint = 312;
				textStateLData.heightHint = 17;
				textState.setLayoutData(textStateLData);
				textState.setEditable(false);
			}
			{
				labelPublicDns = new Label(dialogShell, SWT.NONE);
				GridData labelPublicDnsLData = new GridData();
				labelPublicDnsLData.widthHint = 71;
				labelPublicDnsLData.heightHint = 17;
				labelPublicDns.setLayoutData(labelPublicDnsLData);
				labelPublicDns.setText("PublicDns");
			}
			{
				GridData textPublicDnsLData = new GridData();
				textPublicDnsLData.widthHint = 292;
				textPublicDnsLData.heightHint = 17;
				textPublicDns = new Text(dialogShell, SWT.BORDER);
				textPublicDns.setLayoutData(textPublicDnsLData);
				textPublicDns.setEditable(false);
			}
			{
				labelPrivateDns = new Label(dialogShell, SWT.NONE);
				labelPrivateDns.setText("PrivateDns");
			}
			{
				GridData textPrivateDnsLData = new GridData();
				textPrivateDnsLData.widthHint = 308;
				textPrivateDnsLData.heightHint = 17;
				textPrivateDns = new Text(dialogShell, SWT.BORDER);
				textPrivateDns.setLayoutData(textPrivateDnsLData);
				textPrivateDns.setEditable(false);
			}
			{
				labelType = new Label(dialogShell, SWT.NONE);
				labelType.setText("Type");
			}
			{
				GridData textTypeLData = new GridData();
				textTypeLData.widthHint = 291;
				textTypeLData.heightHint = 17;
				textType = new Text(dialogShell, SWT.BORDER);
				textType.setLayoutData(textTypeLData);
				textType.setEditable(false);
			}
			{
				LabelDate = new Label(dialogShell, SWT.NONE);
				LabelDate.setText("Date");
			}
			{
				GridData textDateLData = new GridData();
				textDateLData.widthHint = 310;
				textDateLData.heightHint = 17;
				textDate = new Text(dialogShell, SWT.BORDER);
				textDate.setLayoutData(textDateLData);
				textDate.setEditable(false);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("labelMyId");
			}
			{
				GridData textMyIdLData = new GridData();
				textMyIdLData.widthHint = 297;
				textMyIdLData.heightHint = 17;
				textMyId = new Text(dialogShell, SWT.BORDER);
				textMyId.setLayoutData(textMyIdLData);
			}
			{
				labelIp = new Label(dialogShell, SWT.NONE);
				labelIp.setText("Public Ip");
			}
			{
				GridData textIpLData = new GridData();
				textIpLData.widthHint = 304;
				textIpLData.heightHint = 17;
				textIp = new Text(dialogShell, SWT.BORDER);
				textIp.setLayoutData(textIpLData);
				textIp.setEditable(false);
			}
			{
				composite1 = new Composite(dialogShell, SWT.NONE);
				GridLayout composite1Layout = new GridLayout();
				composite1Layout.makeColumnsEqualWidth = true;
				composite1.setLayout(composite1Layout);
			}
			{
				composite2 = new Composite(dialogShell, SWT.NONE);
				GridLayout composite2Layout = new GridLayout();
				composite2Layout.makeColumnsEqualWidth = true;
				composite2.setLayout(composite2Layout);
			}
			{
				composite3 = new Composite(dialogShell, SWT.NONE);
				GridLayout composite3Layout = new GridLayout();
				composite3Layout.makeColumnsEqualWidth = true;
				composite3.setLayout(composite3Layout);
			}
			{
				buttonAccept = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				GridData buttonAcceptLData = new GridData();
				buttonAcceptLData.widthHint = 170;
				buttonAcceptLData.heightHint = 27;
				buttonAccept.setLayoutData(buttonAcceptLData);
				buttonAccept.setText("Accept");
				buttonAccept.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent event) {				    	
						dialogShell.close();
					}
				});
			}
			{
				labelUserData = new Label(dialogShell, SWT.NONE);
				labelUserData.setText("User-Data");
			}
			{
				GridData textUserDataLData = new GridData();
				textUserDataLData.widthHint = 300;
				textUserDataLData.heightHint = 367;
				textUserData = new Text(dialogShell, SWT.MULTI | SWT.WRAP);
				textUserData.setLayoutData(textUserDataLData);
			}

			if (instance != null){
				textAmi.setText(instance.getImageId());
				textId.setText(instance.getInstanceId());
				textPrivateDns.setText(instance.getPrivateDnsName());
				textPublicDns.setText(instance.getDnsName());
				textState.setText(instance.getState());
				textType.setText(instance.getInstanceType().getTypeId());
				SimpleDateFormat format = new SimpleDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa");
				
				String  date = format.format(instance.getLaunchTime().getTime());
				textDate.setText(date);
				
				textIp.setText(IpHelper.getIp(instance.getDnsName()));
				
				//textUserData.setText(monitorInstance.getUserData());
				
				
			}
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	

	public MonitorEc2Instance getMonitorInstance() {
		return monitorInstance;
	}

	public void setMonitorInstance(MonitorEc2Instance monitorInstance) {
		this.monitorInstance = monitorInstance;
		instance = monitorInstance.getInstance();
	}
	
}
